Fabric-client : 하이퍼레저 패브릭 기반 블록체인 네트워크와 통신을 가능하게 하는 핵심 구성요소다. 피어, 오더러 관리 및 이벤트 처리 등 다양한 API를 제공한다. 새로운 채널 생성, 피어 노드의 채널 참여, 피어에 체인코드 설치 및 인스턴스화, 트랜잭션 제출, 트랜잭션 또는 블록의 원장 조회등.
Fabric-CA-Client: 사용자 관리에 사용된다. 새로운 사용자 등록, 하이퍼레저 패브릭 서버에서 서명한 등록 인증서 발급, 기존 사용자 인증서 폐기등이 있다.
Fabric-Network(API) : 플러그할 수 있는 구성 요소에 대한 API를 제공한다. SDK에서 사용하는 주요 인터페이스인 CryptoSuite, key, keyValueStore를 기본적으로 내장하고 있다.
하이퍼레저 패브릭 SDK는 하이퍼레저 패브릭 네트워크와 gRPC를 통해 통신하는데, gRPC는 구글에서 개발한 HTTP 기반 RPC 프레임워크로, 더 적은 리소스를 통해 네트워크 통신의 효율성을 극대화해 성능을 강화한 통신 프로토콜이다.
먼저 hyperledger fabric server도 node js 로 작성 할 것이기 때문에, package.json을 작성해준다.
// capture network variables from config.json const configPath = path.join(process.cwd(), 'config.json'); const configJSON = fs.readFileSync(configPath, 'utf8'); const config = JSON.parse(configJSON); var connection_file = config.connection_file; var appAdmin = config.appAdmin; var appAdminSecret = config.appAdminSecret; var userName = config.userName; var orgMSPID = config.orgMSPID; var caName = config.caName;
const filePath = path.join(process.cwd(), '/connection.yaml'); let fileContents = fs.readFileSync(filePath, 'utf8'); let connectionFile = yaml.safeLoad(fileContents);
asyncfunctionmain() { try { // Create a new CA client for interacting with the CA. const caURL = connectionFile.certificateAuthorities[caName].url; const ca = new FabricCAServices(caURL); // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); const wallet = new FileSystemWallet(walletPath);
// Check to see if we've already enrolled the admin user. const adminExists = await wallet.exists(userName); if (adminExists) { console.log('An identity for the admin user "admin" already exists in the wallet'); return; }
// Enroll the admin user, and import the new identity into the wallet.
const enrollment = await ca.enroll({ enrollmentID: appAdmin, enrollmentSecret: appAdminSecret }); const identity = X509WalletMixin.createIdentity(orgMSPID, enrollment.certificate, enrollment.key.toBytes()); wallet.import(userName, identity); console.log('msg: Successfully enrolled admin user ' + userName + ' and imported it into the wallet');